<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('检查模板列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>模板名称：</label>
                                <input type="text" name="templateName"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="add()" shiro:hasPermission="control:template:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="control:template:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('control:template:edit')}]];
        var removeFlag = [[${@permission.hasPermi('control:template:remove')}]];
        var prefix = ctx + "control/template";
        var download = ctx + "sys/common/download/"

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/deleteBatch",
                exportUrl: prefix + "/export",
                modalName: "检查模板",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id', 
                    title: 'id',
                    visible: false
                },
                {
                    field: 'templateName', 
                    title: '模板名称'
                },
                {
                    field: 'templatePath', 
                    title: '文档下载',
                    formatter: function(value, row, index) {
                        if(value){
                            return '<a href="'+ download + value +'" title="'+ row.templateName +'">模板下载</a>'
                        }else{
                            return "-";
                        }
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-info btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="seeWord(\'' + row.id + '\')"><i class="fa fa-search"></i>查看</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        // 修改信息
        function edit(id) {
            open("编辑检查模板", $.common.setURL(prefix + "/edit/" + id));
        }

        function add() {
            open("添加检查模板", $.operate.addUrl());
        }

        function open(title, url) {
            layer.open({
                type: 2,
                area: ['800px', '300px'],
                fix: false,
                maxmin: true,
                shade: 0.3,
                title: title,
                content: url,
                btn: ['确定', '关闭'],
                shadeClose: true,
                yes: function(index, layero) {
                    var iframeWin = layero.find('iframe')[0];
                    iframeWin.contentWindow.submitHandler(index, layero);
                },
                cancel: function(index) {
                    return true;
                }
            });
        }

        function seeWord(id) {
            var url = prefix + '/see/' + id;
            var _height = ($(window).height() - 50);
            $.get($.common.setURL(url), function (res) {
                layer.open({
                    title: "模板查看",
                    type: 1,
                    fix: false,
                    area: ['1000px', _height + 'px'],
                    content: res,
                    cancel: function () {
                        reload();
                    }
                });
                const $base = $("#layui-layer1").children("div").children("div");
                const $table = $base.children("table");
                $table.css("margin", "auto");
                $table.find("p").css("text-align", "center").find("input[type='checkbox']").css("margin-right", "5px");

                const $p = $($base.children("p").has('span')[1]);
                const width = ($p.width() - $table.width())/2;
                $p.css("padding-left", width + "px");
                console.log($base);
            });
        }

        function reload() {
            var target = $(window.parent.document.getElementsByClassName("William_iframe")[1]);
            var url = target.attr('src');
            target.attr('src', url).ready();
        }
    </script>
</body>
</html>